<template>
	<view class="allhw bg-grey">
		<im-navBar backAction ref="navBarRef" :navbarText="navbarText" :rightBtn="rightBtn" @rightActionSelectedFu="navBarRightActionSelectedFu"></im-navBar>
		<view class="search-div"><im-search-input @inputChange="inputChange" :value="searchKey"></im-search-input></view>
		<scroll-view scroll-y scroll-with-animation class="main-class" nable-back-to-top>
			<view v-if="chatList.length > 0">
				<!-- 	[{
						id:1,
						name:'波多野溪子',
						nickName:'波多野溪子',
						avatar:'https://cdn.quasar.dev/img/avatar.png',
						type:ImEnum.OtherEnum.USER_TYPE.USER,
						lastChatTime:'10:22',
						lastChatContent:"你好啊，傻逼",
					}] -->
				<view class="list-item" v-for="(item, index) in chatList" :key="index">
					<tui-divider height="2" color="black"></tui-divider>
					<tui-swipe-action :actions="swipeActions" @click="deleteChat(index)">
						<template v-slot:content>
							<view class="tui-list-item" @click="detail(item)">
								<image :src="item.avatar" class="tui-img"></image>
								<view class="item-box">
									<view class="item-title">{{ item.nickName }}</view>
									<view class="item-time text-cut">{{ item.lastChatContent }}</view>
								</view>
								<view class="tui-msg-right tui-right-dot">
									<view class="item-time">{{ item.lastChatTime }}</view>
									<view class="action">
										<tui-button @click="actionFu(item)" v-if="item.type === friendType" class="action-button" :size="20" width="80rpx" height="40rpx">操作</tui-button>
										<view v-else class="item-time">已添加</view>
									</view>
								</view>
							</view>
						</template>
					</tui-swipe-action>
				</view>
			</view>
			<!-- 没有会话 -->
			<tui-no-data class="im-nodata" v-else imgUrl="/static/img/img_nodata.png" btnColor="#4caf50">暂无</tui-no-data>
		</scroll-view>
		<im-copy-right></im-copy-right>
	</view>
</template>

<script>
import ImEnum from '../../../sdk/enums/index.js';
export default {
	data() {
		return {
			showSearchModel: false,
			navbarText: '新朋友',
			friendType :ImEnum.OtherEnum.FRIEND_TYPE.UN_KONW,
			rightBtn: {
				btnUse: true,
				btnText: '添加',
				btnType: 'green'
			},
			swipeActions: [
				{
					name: '删除',
					color: 'white',
					fontsize: '30rpx',
					width: '80',
					background: 'red'
				}
			],
			searchKey: '',
			chatList: [
				{
					id: 1,
					name: '波多野溪子',
					nickName: '波多野溪子',
					avatar: 'https://cdn.quasar.dev/img/avatar.png',
					type: ImEnum.OtherEnum.FRIEND_TYPE.FRIEND,
					lastChatTime: '10:22',
					lastChatContent: '你好啊，傻逼'
				},
				{
					id: 1,
					name: '波多野溪子2',
					nickName: '波多野溪子2',
					avatar: 'https://cdn.quasar.dev/img/avatar.png',
					type: ImEnum.OtherEnum.FRIEND_TYPE.UN_KONW,
					lastChatTime: '10:22',
					lastChatContent: '你好啊，傻逼'
				},
				{
					id: 1,
					name: '波多野溪子3',
					nickName: '波多野溪子3',
					avatar: 'https://cdn.quasar.dev/img/avatar.png',
					type: ImEnum.OtherEnum.FRIEND_TYPE.BLACK_LIST,
					lastChatTime: '10:22',
					lastChatContent: '你好啊，傻逼'
				}
			]
		};
	},
	methods: {
		navBarRightActionSelectedFu() {
			uni.navigateTo({
				url:'./addFriend'
			})
		},
		inputChange(e) {
			this.searchKey = e;
		},
		deleteChat() {},
		detail() {},
		actionFu(item){
			uni.navigateTo({
				url:'./friendInfo?agree_model=true&userAccountNum='+item.id
			})
		},
	}
};
</script>

<style scoped>
.main-class {
	height: calc(100vh - 100rpx);
	width: 95%;
}
.search-div {
	margin-top: 60rpx;
	width: 100%;
	height: 100rpx;
	line-height: 100rpx;
}
.im-nodata {
	position: absolute;
	z-index: 2;
	top: 50vh;
}

.tui-list-item {
	padding: 10rpx 10rpx;
	display: flex;
	align-items: item;
}

.item-img {
	height: 80rpx;
	width: 80rpx;
	display: block;
}

.item-box {
	margin-left: 30rpx;
	flex: 1;
	width: 70%;
	display: flex;
	flex-direction: column;
	justify-content: space-between;
}

.item-title {
	font-size: 30rpx;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.item-time {
	width: 98%;
	color: #999;
	font-size: 20rpx;
}
.list-item {
	border-radius: 2%;
	margin-left: 5%;
}
.action{
	margin-top: 12rpx;
}
.action-button {
	margin-top: 10rpx;
}
</style>
